const mongoose = require('mongoose')
const Schema = mongoose.Schema
const { name } = require('../public/javascripts/utils');

const schema = new Schema({
  content: { type: String, required: true }, // 消息内容
  senderId: { type: Schema.Types.ObjectId, ref: 'users', required: true }, // 发送者
  receiverId: { type: Schema.Types.ObjectId, ref: 'users', required: true }, // 接收者
  createdAt: { type: Date, default: Date.now }, // 创建时间
  isRead: { type: Boolean, default: false } // 是否已读
})
// 创建复合索引
schema.index({ senderId: 1, receiverId: 1, createdAt: -1 });
module.exports = mongoose.model(name(__filename), schema)